package com.briup.searchengine.handle;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.*;

import java.io.IOException;
import java.util.ArrayList;

/**
 * @author adam
 * @date 2022/6/13
 * 为了将来在做连接的时候能够更明确数据从那张表获取  先给表加一个标记
 * 在列族 page里边  加一个列i  clean_webpage 的值为a  rank_result的值为b
 */
public class Step4_AddIdentity {
    public static void main(String[] args) throws IOException {
        Configuration conf = HBaseConfiguration.create();
        Connection connection = ConnectionFactory.createConnection(conf);
        Table table1 = connection.getTable(TableName.valueOf("clean_webpage"));
        Table table2 = connection.getTable(TableName.valueOf("rank_result"));
        //    先扫描到所有的行 然后给所有的行添加一个列 i
        ResultScanner resultScanner1 = table1.getScanner(new Scan());
        ResultScanner resultScanner2 = table2.getScanner(new Scan());
        ArrayList<Put> list1 = new ArrayList<>();
        ArrayList<Put> list2 = new ArrayList<>();
        for (Result result : resultScanner1) {
            Put put = new Put(result.getRow());
            put.addColumn("page".getBytes(), "i".getBytes(), "a".getBytes());
            System.out.print("a");
            list1.add(put);
        }
        for (Result result : resultScanner2) {
            Put put = new Put(result.getRow());
            put.addColumn("page".getBytes(), "i".getBytes(), "b".getBytes());
            System.out.print("b");
            list2.add(put);
        }
        table1.put(list1);
        table2.put(list2);
    }
}
